home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
commands
/
make
/
make.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-15
|
17KB
|
714 lines
/*************************************************************************
*
* m a k e : m a k e . c
*
* Do the actual making for make plus system dependent stuff
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 01.07.89 $<,$* bugs fixed RAL
* 3 23.08.89 (time_t)time((time_t*)0) bug fixed, N_EXISTS added RAL
* 4 30.08.89 leading sp. in cmd. output eliminated, indention ch. PSH,RAL
* 5 03.09.89 :: time fixed, error output -> stderr, N_ERROR intr.
* fixed LZ elimintaed RAL
* 6 07.09.89 implmacro, DF macros,debug stuff added RAL
* 7 09.09.89 tos support added PHH,RAL
* 8 17.09.89 make1 arg. fixed, N_EXEC introduced RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
static bool execflag;
/*
* Exec a shell that returns exit status correctly (/bin/esh).
* The standard EON shell returns the process number of the last
* async command, used by the debugger (ugg).
* [exec on eon is like a fork+exec on unix]
*/
int dosh(string, shell)
char *string;
char *shell;
{
int number;
#ifdef unix
return system(string);
#endif
#ifdef tos
return Tosexec(string);
#endif
#ifdef eon
return ((number = execl(shell, shell,"-c", string, 0)) == -1) ?
-1: /* couldn't start the shell */
wait(number); /* return its exit status */
#endif
#ifdef os9
int status, pid;
strcat(string, "\n");
if ((number = os9fork(shell, strlen(string), string, 0, 0, 0)) == -1)
return -1; /* Couldn't start a shell */
do {
if ((pid = wait(&status)) == -1)
return -1; /* child already died!?!? */
} while (pid != number);
return status;
#endif
}
/*
* Do commands to make a target
*/
void docmds1(np, lp)
struct name *np;
struct line *lp;
{
register char *q;
register char *p;
register struct cmd *cp;
bool ssilent;
bool signore;
int estat;
char *shell;
if (*(shell = getmacro("SHELL")) == '\0')
#ifdef eon
shell = ":bin/esh";
#endif
#ifdef unix
shell = "/bin/sh";
#endif
#ifdef os9
shell = "shell";
#endif
#ifdef tos
shell = "DESKTOP"; /* TOS has no shell */
#endif
for (cp = lp->l_cmd; cp; cp = cp->c_next) {
execflag = TRUE;
strcpy(str1, cp->c_cmd);
expmake = FALSE;
expand(&str1s);
q = str1;
ssilent = silent;
signore = ignore;
while ((*q == '@') || (*q == '-')) {
if (*q == '@') /* Specific silent */
ssilent = TRUE;
else /* Specific ignore */
signore = TRUE;
q++; /* Not part of the command */
}
for (p=q; *p; p++) {
if (*p == '\n' && p[1] != '\0') {
*p = ' ';
if (!ssilent)
fputs("\\\n", stdout);
}
else if (!ssilent)
putchar(*p);
}
if (!ssilent)
printf("\n");
if (domake || expmake) { /* Get the shell to execute it */
if ((estat = dosh(q, shell)) != 0) {
if (estat == -1)
fatal("Couldn't execute %s", shell,0);
else if (signore)
printf("%s: Error code %d (Ignored)\n", myname, estat);
else {
fprintf(stderr,"%s: Error code %d\n", myname, estat);
if (!(np->n_flag & N_PREC))
if (unlink(np->n_name) == 0)
fprintf(stderr,"%s: '%s' removed.\n", myname, np->n_name);
if (!conterr) exit(estat);
np->n_flag |= N_ERROR;
return;
}
}
}
}
}
void docmds(np)
struct name *np;
{
register struct line *lp;
for (lp = np->n_line; lp; lp = lp->l_next)
docmds1(np, lp);
}
#ifdef tos
/*
* execute the command submitted by make,
* needed because TOS has no internal shell,
* so we use Pexec to do the job
* v 1.1 of 10/sep/89 by yeti
*/
#define DELM1 ';'
#define DELM2 ' '
#define DELM3 ','
int Tosexec(string)
char *string;
{
register char *help, *help2, c;
register unsigned char l=1;
char progname[80], command[255], plain[15];
static char **envp,*env;
register int error,i;
/* generate strange TOS environment (RAL) */
for ( i = 0, envp = environ; *envp; envp++) i += strlen(*envp) +1;
if ((env = malloc(i+1)) == (char *)0)
fatal("No memory for TOS environment",(char *)0,0);
for ( envp = environ, help = env; *envp; envp++) {
strcpy ( help, *envp);
while ( *(help++)) ;
}
*help = '\0';
help = progname;
while((*help++=*string++) != ' '); /* progname is command name */
*--help = '\0';
l = strlen(string); /* build option list */
command[0] = l; /* TOS likes it complicated */
strcpy(&command[1],string);
if ((error = (int) Pexec(0,progname,command,env)) != -33) {
free(env);
return(error);
}
/* could'nt find program, try to search the PATH */
if((help=strrchr(progname,'\\')) != (char *) 0) /* just the */
strcpy(plain,++help); /* name */
else if((help=strrchr(progname,'/')) != (char *) 0)
strcpy(plain,++help);
else if((help=strrchr(progname,':')) != (char *) 0)
strcpy(plain,++help);
else
strcpy(plain,progname);
if(*(help=getmacro("PATH")) == '\0') {
free(env);
return(-33);
}
c = 1;
while(c)
{ help2 = &progname[-1];
i = 0;
while((c=*help++) != '\0' && i<80 && c != DELM1
&& c != DELM2 && c != DELM3)
*++help2 = c, i++;
*++help2 = '\\';
strcpy(++help2,plain);
if((error=(int) Pexec(0,progname,command,env))!=-33) {
free(env);
return(error);
}
}
free(env);
return(-33);
}
/* (stolen from ZOO -- thanks to Rahul Dehsi)
Function mstonix() accepts an MSDOS format date and time and returns
a **IX format time. No adjustment is done for timezone.
*/
time_t mstonix (date, time)
unsigned int date, time;
{
int year, month, day, hour, min, sec, daycount;
time_t longtime;
/* no. of days to beginning of month for each month */
static int dsboy[12] = { 0, 31, 59, 90, 120, 151, 181, 212,
243, 273, 304, 334};
if (date == 0 && time == 0) /* special case! */
return (0L);
/* part of following code is common to zoolist.c */
year = (((unsigned int) date >> 9) & 0x7f) + 1980;
month = ((unsigned int) date >> 5) & 0x0f;
day = date & 0x1f;
hour = ((unsigned int) time >> 11)& 0x1f;
min = ((unsigned int) time >> 5) & 0x3f;
sec = ((unsigned int) time & 0x1f) * 2;
/* DEBUG and leap year fixes thanks to Mark Alexander <uunet!amdahl!drivax!alexande>*/
#ifdef DEBUG
printf ("mstonix: year=%d month=%d day=%d hour=%d min=%d sec=%d\n",
year, month, day, hour, min, sec);
#endif
/* Calculate days since 1970/01/01 */
daycount = 365 * (year - 1970) + /* days due to whole years */
(year - 1969) / 4 + /* days due to leap years */
dsboy[month-1] + /* days since beginning of this year */
day-1; /* days since beginning of month */
if (year % 4 == 0 &&
year % 400 != 0 && month >= 3) /* if this is a leap year and month */
daycount++; /* is March or later, add a day */
/* Knowing the days, we can find seconds */
longtime = daycount * 24L * 60L * 60L +
hour * 60L * 60L + min * 60 + sec;
return (longtime);
}
#endif tos
#ifdef os9
/*
* Some stuffing around to get the modified time of a file
* in an os9 file system
*/
void getmdate(fd, tbp)
int fd;
struct sgtbuf *tbp;
{
struct registers regs;
static struct fildes fdbuf;
regs.rg_a = fd;
regs.rg_b = SS_FD;
regs.rg_x = &fdbuf;
regs.rg_y = sizeof (fdbuf);
if (_os9(I_GETSTT, ®s) == -1) {
errno = regs.rg_b & 0xff;
return -1;
}
if (tbp)
{
_strass(tbp, fdbuf.fd_date, sizeof (fdb